package controllers;

import client.gui.panels.PanelIF;
import client.gui.panels.TrackTicket;
import entities.Message;
import entities.Ticket;

/**
 * @author Meir
 *
 */
public class TrackTicketController implements ControllerIF {
	
	/**
	 * the track ticket panel
	 */
	private TrackTicket trackTicket;
	
	/**
	 * the main panel controller
	 */
	private MainPanelController mainPanelController;
	
	/**
	 * A structure to hold all the information inserted 
	 */
	private Ticket ticket;
	
	
	
	public TrackTicketController(MainPanelController mainPanelController) {
		this.mainPanelController = mainPanelController;
		this.mainPanelController.setInnerPanelController(this);
	}	
	
	/* (non-Javadoc)
	 * @see controllers.ControllerIF#getPanel()
	 */
	@Override
	public PanelIF getPanel() {
		return trackTicket;
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#setPanel(client.gui.panels.PanelIF)
	 */
	@Override
	public void setPanel(PanelIF panel) {
		this.trackTicket = (TrackTicket) panel;
		trackTicket.setController(this);
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#action()
	 */
	@Override
	public void action() {
		Long ticketId = trackTicket.getRequestedTicketId();
		mainPanelController.ticketTrackingRequest(ticketId);
	}

	/* (non-Javadoc)
	 * @see controllers.ControllerIF#decipherMessage(entities.Message)
	 */
	@Override
	public void decipherMessage(Message message) {
		Ticket ticket = (Ticket)message.getObject();
		switch(ticket.getState()) {
		case "EVALUATION_REPORT":
			trackTicket.InsertDetails("EVALUATION", ticket.getEvaluationReportStage().getDurationDate());
			break;
		case "REVIEW":
			trackTicket.InsertDetails("REVIEW", ticket.getReviewDecisionStage().getDurationDate());
			break;
		case "EXECUTION_REPORT":
			trackTicket.InsertDetails("EXECUTION", ticket.getExecutionStage().getDurationDate());
			break;
		case "VERIFICATION_REPORT":
			trackTicket.InsertDetails("VERIFICATION", ticket.getVerificationStage().getDurationDate());
			break;
		default:
			trackTicket.InsertDetails(null, null);
			break;
		}
	}

}
